#include "Environment.h"

using namespace std; 

Environment::Environment(){
  _operations = MAXOPERATIONS;
  _computation = 0; 
  _result = 0; 
  _nbThread = 4;
  _thread = NULL; 
}

Environment::Environment(int operations){
  _operations = operations; 
  _computation = 0; 
  _result=0; 
  _nbThread = 4;
  _thread = NULL; 
}

Environment::~Environment(){
  free(_thread);
}

long Environment::getOperations(){
  return _operations; 
}
int Environment::getComputation(){
  return _computation; 
}
pthread_t * Environment::getThread(){
  return _thread; 
}

void Environment::setOperations(long operations){
  _operations = operations; 
 }

void Environment::setOperation(string value){
  const char * tmp = value.c_str();
  _operations = atol(tmp);  
}

void Environment::setMaxOperation(){
  _operations = MAXOPERATIONS; 
}

void Environment::setComputation(int computation){
  _computation = computation; 
}

void Environment::setComputation(string value){
  string valInt = "int";
  if(!value.compare(valInt)){
    setComputation(1);
  } else if (!value.compare("float")){
    setComputation(2); 
  } else {
    setComputation(0);
  }
}

void Environment::setThread(pthread_t* thread){
  _thread = thread;
}

void Environment::setThread(string value){
  if(!value.compare("1")){
    _nbThread = 1; 
  } else if (!value.compare("2")){
    _nbThread = 2; 
  } 
  _thread =(pthread_t*) malloc(sizeof(pthread_t)*_nbThread); 
}

void Environment::toPrint(){

  cout << "Computation is " << _computation << endl; 
  cout << "Number of operation is " << _operations << endl; 
  cout << "Number of thread is " << sizeof(_thread)/sizeof(pthread_t) << "  " << _nbThread << endl; 
  cout << "Result is " << _result << endl ; 
}

int Environment::getNbThread(){
  return _nbThread;
}
